package com.example.barcodeapp.ui.wode;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.cardview.widget.CardView;


import com.bumptech.glide.Glide;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.example.barcodeapp.MainActivity;
import com.example.barcodeapp.R;
import com.example.barcodeapp.base.BaseFragment;
import com.example.barcodeapp.common.Constants;
import com.example.barcodeapp.interfaces.IBasePersenter;
import com.example.barcodeapp.interfaces.own.IOwn;
import com.example.barcodeapp.persenter.OnePresenterWoDe;
import com.example.barcodeapp.ui.wode.activity.ChongZhiActivity;
import com.example.barcodeapp.ui.wode.activity.DiscountActivity;
import com.example.barcodeapp.interfaces.own.IOwn;
import com.example.barcodeapp.persenter.OnePresenterWoDe;
import com.example.barcodeapp.ui.wode.activity.DiscountActivity;
import com.example.barcodeapp.ui.wode.activity.HotActivity;
import com.example.barcodeapp.ui.wode.activity.HotActivity;
import com.example.barcodeapp.ui.wode.activity.KeChengActivity;
import com.example.barcodeapp.ui.wode.activity.OrderformActivity;
import com.example.barcodeapp.ui.wode.activity.PersonalActivity;
import com.example.barcodeapp.ui.wode.activity.ShezhiActivity;
import com.example.barcodeapp.ui.wode.activity.WoDeKechengBaoActivity;
import com.example.barcodeapp.ui.wode.activity.WoDeShouCangActivity;
import com.example.barcodeapp.ui.wode.activity.WoDeYuEActivity;
import com.example.barcodeapp.ui.wode.activity.WorkActivity;
import com.example.barcodeapp.ui.wode.activity.ZOrderActivity;
import com.example.barcodeapp.ui.wode.bean.WoDeZhuYeBean;
import com.example.barcodeapp.utils.GlideUtile;

import java.util.logging.Handler;
import com.example.barcodeapp.ui.wode.activity.WoDeShouCangActivity;
import com.example.barcodeapp.ui.wode.activity.WoDeYuEActivity;
import com.example.barcodeapp.ui.wode.activity.WorkActivity;
import com.example.barcodeapp.ui.wode.bean.WoDeZhuYeBean;
import com.example.barcodeapp.utils.GlideUtile;
import com.example.barcodeapp.utils.SystemUtils;

import butterknife.BindView;


public class FragmentWoDe extends BaseFragment<IOwn.Persenterwode> implements IOwn.Viewwode, View.OnClickListener {
    @BindView(R.id.wode_name)
    TextView wodeName;
    @BindView(R.id.wode_dianhua)
    TextView wodeDianhua;
    @BindView(R.id.wode_name_gai)
    ImageView wodeNameGai;
    @BindView(R.id.wode_touxiang)
    ImageView wodeTouxiang;
    @BindView(R.id.cardView)
    CardView cardView;
    @BindView(R.id.wode_jifen)
    TextView wodeJifen;
    @BindView(R.id.shezhi)
    RelativeLayout shezhi;
    @BindView(R.id.wode_yue)
    TextView wodeYue;
    @BindView(R.id.cardview2)
    CardView cardview2;
    @BindView(R.id.kechengguanli)
    LinearLayout kechengguanli;
    @BindView(R.id.wdoezuoye)
    LinearLayout wdoezuoye;
    @BindView(R.id.wodehuodong)
    LinearLayout wodehuodong;
    @BindView(R.id.wodeshouchang)
    LinearLayout wodeshouchang;
    @BindView(R.id.yuyuekecheng)
    LinearLayout yuyuekecheng;
    @BindView(R.id.wodedingdan)
    LinearLayout wodedingdan;
    @BindView(R.id.wodekechengbao)
    LinearLayout wodekechengbao;
    @BindView(R.id.youhuijuan)
    LinearLayout youhuijuan;
    @BindView(R.id.cardview3)
    CardView cardview3;
    @BindView(R.id.zuoye_img)
    ImageView zuoyeImg;
    @BindView(R.id.huodong_img)
    ImageView huodongImg;
    @BindView(R.id.youhuijuan_img)
    ImageView youhuijuanImg;
    @BindView(R.id.kechengbao_img)
    ImageView kechengbaoImg;
    @BindView(R.id.cardview4)
    CardView cardview4;
    @BindView(R.id.yue)
    LinearLayout yue2;
    @BindView(R.id.jiazhang)
    RelativeLayout jiazhang;
    @BindView(R.id.laoshi)
    RelativeLayout laoshi;
    @BindView(R.id.kefu)
    RelativeLayout kefu;
    @BindView(R.id.ll_wode)
    LinearLayout mLLWode;
    private MainActivity mActivity;
    private String yue;

    @Override
    protected int getLayout() {
        return R.layout.fragment_wo_de;
    }

    @Override
    protected void initView() {
        mActivity = (MainActivity) getActivity();
        GlideUtile.setImgCircle(getActivity(), wodeTouxiang, R.drawable.zhuang);
        kechengguanli.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(context, KeChengActivity.class));
            }
        });
        initListener();
    }

    private void initListener() {
        cardView.setOnClickListener(this);
        wodedingdan.setOnClickListener(this);
        wdoezuoye.setOnClickListener(this);
        shezhi.setOnClickListener(this);
        youhuijuan.setOnClickListener(this);
        wodehuodong.setOnClickListener(this);
        yuyuekecheng.setOnClickListener(this);
        yue2.setOnClickListener(this);
        mLLWode.setOnClickListener(this);
        wodeshouchang.setOnClickListener(this);
        wodekechengbao.setOnClickListener(this);
    }

    @Override
    protected OnePresenterWoDe initPersenter() {
        return new OnePresenterWoDe();
    }

    @Override
    protected void initData() {
        persenter.getwode(5);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.cardView://个人资料
                startActivityForResult(new Intent(mActivity, PersonalActivity.class), 1);
                break;
            case R.id.wodedingdan://我的订单
                startActivity(new Intent(mActivity, OrderformActivity.class));
                break;
            case R.id.wdoezuoye://我的作业
                startActivity(new Intent(mActivity, WorkActivity.class));
                break;
            case R.id.shezhi://设置
                startActivity(new Intent(mActivity, ShezhiActivity.class));
                break;
            case R.id.youhuijuan://优惠券
                startActivity(new Intent(mActivity, DiscountActivity.class));
                break;
            case R.id.wodehuodong://我的活动
//                startActivity(new Intent(mActivity, HotActivity.class));
                startActivity(new Intent(mActivity, HotActivity.class));
                break;
            case R.id.yuyuekecheng://预约课程
//                startActivity(new Intent(mActivity, ToMakeAnAppointmentCourseActivity.class));
                break;
            case R.id.wodekechengbao://kechengbao
              startActivity(new Intent(mActivity, WoDeKechengBaoActivity.class));
                break;
            case R.id.yue://预约课程
//                startActivity(new Intent(mActivity, WoDeKechengBaoActivity.class));
                Intent intent = new Intent(context, WoDeYuEActivity.class);
                intent.putExtra("yuee", yue);
                startActivity(intent);
                break;
            case R.id.ll_wode:
                startActivity(new Intent(mActivity,ZOrderActivity.class));
                break;
            case R.id.wodeshouchang://收藏
//                startActivity(new Intent(mActivity, WoDeKechengBaoActivity.class));
                startActivity(new Intent(mActivity, WoDeShouCangActivity.class));
                break;
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (resultCode) {
            case 1://个人资料
                byte[] headImgUris = data.getByteArrayExtra("HeadImgUri");
                String nickName = data.getStringExtra("NickName");
                if (headImgUris != null && headImgUris.length > 0) {
                    Bitmap bitmap = BitmapFactory.decodeByteArray(headImgUris, 0, headImgUris.length);
                    GlideUtile.setImgCircle(getActivity(), wodeTouxiang, bitmap);
                }
                if (nickName != null) {
                    wodeName.setText(nickName);
                }
                break;
        }
    }

    @Override
    public void getwode(WoDeZhuYeBean xiLieKeBean) {
        wodeName.setText(xiLieKeBean.getData().getUserinfo().getName());
        wodeDianhua.setText(xiLieKeBean.getData().getUserinfo().getPhone());
        int round = SystemUtils.px2Dp(context, 100);
        RoundedCorners roundedCorners = new RoundedCorners(round);
        RequestOptions options = RequestOptions.bitmapTransform(roundedCorners);
        Glide.with(this).load(xiLieKeBean.getData().getUserinfo().getImage()).apply(options).into(wodeTouxiang);
        yue = xiLieKeBean.getData().getUserinfo().getYue() + "";
        wodeYue.setText(xiLieKeBean.getData().getUserinfo().getYue() + "");
        wodeJifen.setText(xiLieKeBean.getData().getUserinfo().getJifen() + "");


    }

}